package org.datamining.guha.model.node.iterative;

import org.datamining.guha.model.Formatter;
import org.datamining.guha.model.literal.Literal;
import org.datamining.guha.model.node.Node;
import org.datamining.guha.model.node.NodeFactory;
import org.datamining.guha.model.node.NodeFormatter;

/**
 * Factory provides instances of {@link IterativeNode}.
 * By default the {@link Node}s use {@link NodeFormatter}.
 * 
 * @author Lukas Vlcek
 *
 */
public class IterativeNodeFactory implements NodeFactory {

	private static final IterativeNodeFactory INSTANCE = new IterativeNodeFactory();

	private IterativeNodeFactory() {};
		
	static {
		INSTANCE.formatter = new NodeFormatter();
	}
	
	private Formatter<Node> formatter;
	
	public static IterativeNodeFactory getInstance() { return INSTANCE; }
	
	public Node getNode(Literal l, Node nextLitaralNode,
			Node previousLiteralNode, long frequency) {
		Node n = new IterativeNode(l, nextLitaralNode, previousLiteralNode, frequency);
		if (formatter != null) n.setFormatter(formatter);
		return n;
	}

	public Node getNode(Literal l, Node parent, Node nextLitaralNode,
			Node previousLiteralNode, long frequency) {
		Node n = new IterativeNode(l, parent, nextLitaralNode, previousLiteralNode, frequency);
		if (formatter != null) n.setFormatter(formatter);
		return n;
	}

}
